/**
    package: learn-go
    filename: approach4
    author: diogo@gmail.com
    time: 2022/6/6 10:55
**/
package approach4

import (
	"math/rand"
)

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

const (
	// 6 bits to represent a letters index
	letterIdBits = 6
	// All 1-bits as many as letterIdBits
	letterIdMask = 1<<letterIdBits - 1
)

func randStr(n int) string {
	b := make([]byte, n)
	for i := range b {
		if idx := int(rand.Int63() & letterIdMask); idx < len(letters) {
			b[i] = letters[idx]
			i++
		}
	}
	return string(b)
}

